import Mock from 'mockjs'
import {generateRandomString} from "@/utils/index.js";

let info = {
    code: 0,
    data: null,
    msg: '请求成功'
}
export const userLogin = Mock.mock('/admin/user/login', 'post', ({body}) => {
    const {username, password} = JSON.parse(body)
    if (['admin', 'test'].includes(username)) {
        if (password === '12346789') {
            info.data = {
                id: username === 'admin' ? 1 : 2,
                name: username,
                code: `auth_${username}`,
                nickName: username === 'admin' ? '超级管理员' : '测试人员',
                token: `oAuth ${generateRandomString(256)}`
            }
        } else {
            info.code = 1002
            info.msg = '密码错误'
        }
    } else {
        info.code = 1001
        info.msg = '用户名不存在'
    }
    return info
})